layui.use('table', function () {
    var table = layui.table;

    //方法级渲染
    table.render({
      elem: '#LAY_table_user1'
    , url: 'all_sign'
    , cols: [[
      { field: 'id', title: 'ID', width: 80, sort: true, fixed: true }
      , { field: 'name', title: '姓名', width: 80, sort: true }
      , { field: 'sex', title: '性别', width: 80, sort: true }
      , { field: 'dept', title: '部门', width: 80, sort: true }
      , { field: 'sign_back_time', title: '签退时间', width: 120, sort: true, edit: true }
      , { field: 'sign_back_state', title: '签退状态', width: 120, sort: true, edit: true }
    ]]
      , id: 'testReload1'
      , page: true
      , height: 600
      , size: "lg"
    });
    var $ = layui.$, active = {
      reload: function () {
        var demoReload = $('#demoReload');

        table.reload('testReload1', {
          where: {
            keyword: demoReload.val()
          }
        });
      }
    };
    $('.demoTable .layui-btn').on('click', function () {
      var type = $(this).data('type');
      active[type] ? active[type].call(this) : '';
    });
    table.on('tool(useruv)', function (obj) {
      var data = obj.data;
      if (obj.event === 'detail1') {
        layui.use('layer', function () {
          layer.open({
            type: 2,
            content: ["detail1?id=" + data.id],   //添加页，后台controller转发到指定页
            area: ["480px", "480px"],
            title: ['用户查看'],
            fixed: false,
            //maxmin: true,
            shadeClose: true,
            end: function () {  //刷新页面
              location.reload();
            }
          })
        })
      } else if (obj.event === 'del1') {
        layer.confirm('真的删除行么', function (index) {
          console.log(data);
          $.ajax({
            url: "del1",
            type: "POST",
            data: { "id": data.id },
            dataType: "json",
            success: function (data) {

              if (data.state == 1) {
                //删除这一行
                obj.del();
                //关闭弹框
                layer.close(index);
                layer.msg("删除成功", { icon: 6 });
              } else {
                layer.msg("删除失败", { icon: 5 });
              }
            }
          });
        });
      } else if (obj.event === 'edit1') {
        layui.use('layer', function () {
          layer.open({
            type: 2,
            content: ["edit1?id=" + data.id],   //添加页，后台controller转发到指定页
            area: ["600px", "400px"],
            title: ['用户修改'],
            fixed: false,
            //maxmin: true,
            shadeClose: true,
            end: function () {  //刷新页面
              location.reload();
            }
          })
        })
      }
    });
  });
  function add() {
    layui.use('layer', function () {
      layer.open({
        type: 2,
        content: ["preAdd"],   //添加页，后台controller转发到指定页
        area: ["600px", "400px"],
        title: ['用户添加'],
        fixed: false,
        //maxmin: true,
        shadeClose: true,
        end: function () {  //刷新页面
          location.reload();
        }
      })
    })
  }
